//
//  HMHomeViewController.m
//  仿真开发
//
//  Created by jieChen on 17/3/22.
//  Copyright © 2017年 B.HOPE. All rights reserved.
//

#import "HMHomeViewController.h"
#import "HMWeather.h"
#import <YYModel.h>
#import "HMNetwork.h"
#import "HMWeatherView.h"
#import "HMLunBoView.h"
#import "AppointmentController.h"
#import "HMTeamView.h"
#import "AppointDoctorView.h"


@interface HMHomeViewController ()

//五个挂诊的title
@property (nonatomic, strong)NSArray *titles;

@property (weak, nonatomic) IBOutlet HMWeatherView *weatherView;

@property (weak, nonatomic) IBOutlet HMLunBoView *cycleView;

@property (weak, nonatomic) IBOutlet HMTeamView *teamView;

@property(weak, nonatomic) UIStoryboard *story;
@end

@implementation HMHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor lightGrayColor];

    [self loadWeatherData];
    
    _titles = @[@"肿瘤",@"血液科",@"心血管",@"神经科",@"骨科"];
    
    
}


/**
 添加5个button的点击事件
 */
- (IBAction)touchButton:(UIButton *)sender {
    AppointmentController *appoinView = [[AppointmentController alloc] init];
    appoinView.title = _titles[sender.tag];
    appoinView.tag = sender.tag;
    appoinView.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:appoinView animated:YES];
}

/**
 公益活动入口

 */
- (IBAction)touchButton2:(UIButton *)sender {
    
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:vc animated:YES];
    
    
}


/**
 读取天气数据
 */
- (void) loadWeatherData {
    
    // 天气key
    NSString *key  = @"17IvzuqmKrK1cGwNL6VQebF9";
    
    [[HMNetwork sharedTool] reqeustWithURL:@"http://api.map.baidu.com/telematics/v3/weather"method:@"GET" parameters:@{@"location":@"深圳",@"output":@"json",@"ak":key}  callBack:^(id response) {

        // 字典转模型
        NSArray *result = response[@"results"];
//        NSLog(@"%@",result);
        NSDictionary *resultsDict = result.firstObject;
//        NSLog(@"%@",resultsDict);
        NSArray *weatherData = resultsDict[@"weather_data"];
//        NSLog(@"%@",weatherDataDict);
//        NSDictionary *weatherDataDict = weatherData.firstObject;
        NSArray *modelArray = [NSArray yy_modelArrayWithClass:[HMWeather class] json:weatherData];
//        NSLog(@"%@",modelArray);
//        NSLog(@"%@",weatherDataDict);
//        _model = [NSMutableArray arrayWithArray:modelArray];
        _weatherView.model = modelArray.firstObject;
    
    }];

}



@end
